package com.oauth.facebook.server.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.oauth.logging.RapwavesLogger;
import com.oauth.logging.RapwavesLoggerFactory;
import com.oauth.service.global.ApplicationGlobalServiceAdapter;
import com.oauth.service.global.beans.Birthday;
import com.oauth.service.global.beans.OAuthAccessToken;
import com.oauth.service.global.beans.OAuthRequestToken;
import com.rapwaves.feeds.Feeds;

@Service("facebookGlobalService")
public class FacebookGlobalService extends ApplicationGlobalServiceAdapter {

	private RapwavesLogger logger = RapwavesLoggerFactory.getLogger(this.getClass());
	@Autowired
	private FacebookService facebookService;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.oauth.service.application.global.ApplicationGlobalServiceAdapter#
	 * updateStatus(java.lang.Long, java.lang.String)
	 */
	@Override
	public boolean updateStatus(Long pMemberId, String pStatusText) {
		// mOrkutOAuthService.
		try {
			facebookService.updateStatus(pStatusText, pMemberId);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	
	@Override
	public Feeds getFeeds(Long pMemberId) throws Exception {
		try {
			return facebookService.getFeeds(pMemberId);
		} catch (Exception e) {
			logger.error("Error in fetching facebook feeds",e);
			throw e;
		}
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.oauth.service.application.global.ApplicationGlobalServiceAdapter#
	 * getUpcomingBirthdays(java.lang.Long, int)
	 */
	@Override
	public List<Birthday> getUpcomingBirthdays(Long pMemberId, int pBirthdayInterval) {
		try {
			return facebookService.getUpcomingBirthdays(pMemberId, pBirthdayInterval);
		} catch (Exception e) {
			e.printStackTrace();
			return new ArrayList<Birthday>(1);
		}
	}

	/**
	 * @return
	 * @throws Exception
	 * @see com.oauth.facebook.server.service.FacebookService#getAccessToken()
	 */
	public OAuthAccessToken getAccessToken(OAuthRequestToken requestToken) {
		try {
			return facebookService.getAccessToken(requestToken);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @return
	 * @throws Exception
	 * @see com.oauth.facebook.server.service.FacebookService#getRequestToken()
	 */
	public OAuthRequestToken getRequestToken() {
		try {
			return facebookService.getRequestToken();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
